package com.example.myapplication.tools;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.widget.Toast;

import com.example.myapplication.AppInfo;

/**
 * 作者：Administrator
 * 创建时间：2020/7/1
 */
public class EngineUtils {
    public static void startApplication(Context context, AppInfo appInfo) {
        PackageManager packageManager = context.getPackageManager();
        Intent launchIntentForPackage = packageManager.getLaunchIntentForPackage(appInfo.packageInfo.packageName);
        if (launchIntentForPackage != null) {
            context.startActivity(launchIntentForPackage);
        }else{
            Toast.makeText(context, "该应用没有启动界面", Toast.LENGTH_SHORT).show();
        }
    }

    public static void sharedApplication(Context context, AppInfo item) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "分享的app是 " + item.getAppName(context));
        //切记需要使用Intent.createChooser，否则会出现别样的应用选择框，您可以试试
        shareIntent = Intent.createChooser(shareIntent, "分享到：");
        context.startActivity(shareIntent);
    }
}
